import axios from "axios";

const isDev = process.env.NODE_ENV === "development";

const http = axios.create({
  withCredentials: true,
  headers: {
    // 设置后端需要的传参类型
    "Content-Type": "multipart/form-data",
    "Access-Control-Allow-Origin": "*",
  },
});

const baseAPI = isDev
  ? window.location.origin + "/bapi"
  : "https://api.julyedu.com";
const translateAPI = isDev
  ? window.location.origin + "/tapi"
  : "https://translate.julyedu.com/api";

http.interceptors.request.use((config) => {
  // base api, proxy => api.julyedu.com
  if (config.apiType === "bapi") {
    config.baseURL = baseAPI;
  }
  // translate api, proxy => translate.julyedu.com
  if (config.apiType === "tapi") {
    config.baseURL = translateAPI;
  }
  return config;
});

export default http;
